package com.panopset.compat;

import java.util.ArrayList;
import java.util.List;

/**
 * Standard Integer rotation.
 *
 * @author Karl Dinwiddie
 */
public final class Rotation {

    /**
     * Rotation cache.
     */
    private final List<Integer> cache;

    /**
     *
     * @param min
     *            Minimum.
     * @param max
     *            Maximum.
     * @param start
     *            Start position.
     */
    public Rotation(final int min, final int max, final int start) {
        this(min, max, start, false);
    }

    /**
     *
     * @param min
     *            Minimum.
     * @param max
     *            Maximum.
     * @param start
     *            Start position.
     * @param reverseOrder
     *            Iterate in reverse order.
     */
    public Rotation(final int min, final int max, final int start,
            final boolean reverseOrder) {
        final int size = (max - min) + 1;
        int j = start;
        cache = new ArrayList<Integer>();
        for (int i = 0; i < size; i++) {
            cache.add(j);
            if (reverseOrder) {
                j = j - 1;
                if (j < min) {
                    j = max;
                }
            } else {
                j = j + 1;
                if (j > max) {
                    j = min;
                }
            }
        }
    }

    /**
     * @return List of Integers in specified rotation order.
     */
    public List<Integer> getList() {
        return cache;
    }
}
